import {
	CmdMemory
} from "./structs.slint";
import { UiIo } from "global.slint";
import { TestData } from "test-data.slint";
import { HorizontalBox, LineEdit, Button, TextEdit } from "std-widgets.slint";

export component Memory inherits VerticalLayout {
	in-out property <int> memory_idx;
	if (UiIo.memory_param.length > memory_idx) : VerticalLayout {
		HorizontalBox {
			horizontal-stretch: 0;
			LineEdit {
				width: 120px;
				placeholder-text: "Address";
				text: UiIo.memory_param[root.memory_idx].address;
				edited(txt) => { UiIo.memory_param[root.memory_idx].address = txt; }
			}
			LineEdit {
				width: 80px;
				placeholder-text: "Offset";
				text: UiIo.memory_param[root.memory_idx].offset;
				edited(txt) => { UiIo.memory_param[root.memory_idx].offset = txt; }
			}
			LineEdit {
				width: 80px;
				placeholder-text: "Length";
				text: UiIo.memory_param[root.memory_idx].length;
				edited(txt) => { UiIo.memory_param[root.memory_idx].length = txt; }
			}
			Button {
				text: "U32";
				clicked => { UiIo.probe-memory(root.memory_idx, CmdMemory.ReadU32); }
			}
			Button {
				text: "U16";
				clicked => { UiIo.probe-memory(root.memory_idx, CmdMemory.ReadU16); }
			}
			Button {
				text: "U8";
				clicked => { UiIo.probe-memory(root.memory_idx, CmdMemory.ReadU8); }
			}
			Rectangle {}
		}
		TextEdit {
			read-only: true;
			wrap: no-wrap;
			text: UiIo.memory_param[root.memory_idx].data;
		}
	}
}

